<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>银行系统 - 贷款审批历史</title>
<style>
body {
    font-family: Arial, sans-serif;
    margin: 0;
    padding: 0;
}

.header {
    background-color: #333;
    color: white;
    padding: 20px;
    text-align: center;
}

.navbar {
    background-color: #444;
    overflow: hidden;
}

.navbar a {
    float: left;
    display: block;
    color: white;
    text-align: center;
    padding: 14px 16px;
    text-decoration: none;
}

.navbar a:hover {
    background-color: #555;
}

.navbar a.active {
    background-color: #555;
}

.content {
    padding: 20px;
    max-width: 1200px;
    margin: 0 auto;
}

.loan-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 20px;
}

.loan-table th, .loan-table td {
    border: 1px solid #ddd;
    padding: 12px 15px;
    text-align: left;
}

.loan-table th {
    background-color: #f2f2f2;
    font-weight: bold;
}

.loan-table tr:nth-child(even) {
    background-color: #f9f9f9;
}

.loan-table tr:hover {
    background-color: #f5f5f5;
}

.status-pending { color: #FF9800; }
.status-approved { color: #4CAF50; }
.status-rejected { color: #F44336; }
.status-paid { color: #2196F3; }

.error-message {
    color: #F44336;
    margin: 10px 0;
    padding: 10px;
    background-color: #ffcccc;
    border-radius: 4px;
}

.success-message {
    color: #4CAF50;
    margin: 10px 0;
    padding: 10px;
    background-color: #ccffcc;
    border-radius: 4px;
}
</style>
</head>
<body>
    <div class="header">
        <h1>银行管理系统 - 贷款审批历史</h1>
        <p>欢迎您，<c:out value="${sessionScope.user.username}" /></p>
    </div>
    
    <div class="navbar">
        <a href="totalUser">首页</a>
        <a href="loanApplications">贷款审批</a>
        <a href="adminLoanHistory" class="active">审批历史</a>
        <a href="account">账户管理</a>
        <a href="logout">退出登录</a>
    </div>
    
    <div class="content">
        <h2>贷款审批历史</h2>
        
        <c:if test="${not empty error}">
            <div class="error-message">${error}</div>
        </c:if>
        
        <c:if test="${not empty success}">
            <div class="success-message">${success}</div>
        </c:if>
        
        <c:if test="${not empty loans}">
            <table class="loan-table">
                <tr>
                    <th>贷款编号</th>
                    <th>申请人</th>
                    <th>申请金额</th>
                    <th>申请时间</th>
                    <th>审批时间</th>
                    <th>状态</th>
                    <th>操作</th>
                </tr>
                <c:forEach items="${loans}" var="loan">
                    <tr>
                        <td>${loan.loan_number}</td>
                        <td>${loan.user.real_name}</td>
                        <td>${loan.amount}</td>
                        <td>${loan.create_time}</td>
                        <td>${loan.approval_time}</td>
                        <td>
                            <span class="${loan.statusClass}">${loan.statusDesc}</span>
                            <c:if test="${loan.status == 4 && not empty loan.rejection_reason}">
                                <br><small>原因: ${loan.rejection_reason}</small>
                            </c:if>
                        </td>
                        <td>
                            <a href="${pageContext.request.contextPath}/admin/loanDetail?id=${loan.id}">查看详情</a>
                        </td>
                    </tr>
                </c:forEach>
            </table>
        </c:if>
        
        <c:if test="${empty loans}">
            <p>没有找到贷款审批记录</p>
        </c:if>
    </div>
</body>
</html>